/*
 * $Id: DeepSpaceContentPanel.java 149 2009-05-15 15:24:13Z meyer@alphatec.de $
 * 
 *
 * Copyright 2009 DeltaDesk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package deltadesk.deepspace;

import java.awt.event.KeyEvent;

import deltadesk.deepspace.widget.Text;
import deltadesk.deepspace.widget.box.Box;
import deltadesk.deepspace.widget.box.BoxPanel;
import deltadesk.gui.deltagui.layout.GridLayout;

/**
 * DeepSpaceContentPanel
 * 
 * @author Andreas Meyer
 * @version $Revision: 149 $
 */
public class DeepSpaceContentPanel extends BoxPanel {

	/** Our layout manager. */
	private final GridLayout layout;
	

	/**
	 * Construct the panel.
	 * 
	 * @param rows
	 * @param cols
	 */
	public DeepSpaceContentPanel(final int rows, final int cols) {
		super(rows, cols);
		
		layout = (GridLayout)getLayout();
		
	}

	protected void onKeyEvent(KeyEvent ke) {
		
		System.out.println("DeepSpace got " + ke.getKeyCode());
		
		switch (ke.getKeyCode()) {
		case KeyEvent.VK_1:
			layout.incRows();
			invalidate();
			getParent().setUnrendered();
			break;

		case KeyEvent.VK_2:
			layout.incColumns();
			invalidate();
			getParent().setUnrendered();
			break;

		case KeyEvent.VK_3:
			layout.decRows();
			invalidate();
			getParent().setUnrendered();
			break;

		case KeyEvent.VK_4:
			layout.decColumns();
			invalidate();
			getParent().setUnrendered();
			break;

		case KeyEvent.VK_0:
			layout.setAutoCalcGrid();
			invalidate();
			getParent().setUnrendered();
			break;

		case KeyEvent.VK_N:
			add(new Text("Insert new text box to test boxes and word wrap"));
			break;

		case KeyEvent.VK_R:
			getParent().setUnrendered();
			break;

		case KeyEvent.VK_S:
			Box.nextStyle();
			invalidate();
			getParent().setUnrendered();
			break;

		case KeyEvent.VK_C:
			removeAll();
			getParent().setUnrendered();
			break;
		} // end switch

	}

}
